package com.test.thread.demo1;

/**
 * 先执行打印a1 再打印b1,b2,b3  再打印 a2,a3
 */
public class JiaoTi {

    public static void main(String[] args) {
        Object obj = new Object();

        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    System.out.println("a1");
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("a2");
                    System.out.println("a3");
                }
            }
        });

        Thread b = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    System.out.println("b1");
                    System.out.println("b2");
                    System.out.println("b3");
                    obj.notify();
                }
            }
        });
        a.start();
        b.start();
    }
}